Non-polluting Buffer, Slice and attribute routines

Again on the general problem of non-polluting operations:   Does anyone have the tools to verify whether the routine "suite" below truly avoids the creation of anonymous strings in the string table?

Note that this small suite assumes inclusion ONCE in the outermost scope - preferably via the -C switch in DOORS, making them effective perms.  This is the only way to unsure that their potentially ambiguous (Buffer &b) or (Buffer b) footprints do not cause problems (as discussed elsewhere on the forum).  I have, by the way, checked the correct overloads are called by inserting print statements.  Also I checked the status of the buffer creations/deletions using Mathias's tool for this.  But I have no way of testing whether anonymous strings were created and left in the string table.

//-----------------------------------------------
   Buffer createFrom( Module m, string AttrName )
//-----------------------------------------------
// CONSTRUCTOR: Use instead of creating a buffer and loading it in two steps.
   {
      Buffer x = create
      return (x = m.AttrName)
   }


//---------------------------------------------------
   void copyTo( Module m, string AttrName, Buffer b )
//---------------------------------------------------
// Copies the given buffer directly to the attribute without using strings.
// Tested: Because it is defined FIRST, this overloaded routine will be called
// for ANONYMOUS buffers produced by slicing or inline create.  It therefore
// DELETES the given buffer.
   {
      m.AttrName = tempStringOf b
      delete b
   }


//----------------------------------------------------
   void copyTo( Module m, string AttrName, Buffer &b )
//----------------------------------------------------
// Copies the given buffer directly to the attribute without using strings.
// Tested: Because it is defined SECOND, this overloaded routine will be called
// for NAMED buffers produced outside the statment containing the call.  The buffer
// is therfore NOT deleted.  A seperate delete of the buffer must occur at some point.
   {
      m.AttrName = tempStringOf b
   }


//----------------------------------
   void copyTo(string &s, Buffer b )
//----------------------------------
// Copies the given buffer directly to the given string.
// Tested: Because it is defined FIRST, this overloaded routine will be called
// for ANONYMOUS buffers produced by slicing or inline create.  It therefore
// DELETES the given buffer.
   {
      s = stringOf b
      delete b
   }


//------------------------------------
   void copyTo( string &s, Buffer &b )
//------------------------------------
// Copies the given buffer directly to the given string.
// Tested: Because it is defined SECOND, this overloaded routine will be called
// for NAMED buffers produced outside the statment containing the call.  The buffer
// is therfore NOT deleted.  A seperate delete of the buffer must occur at some point.
   {
      s = stringOf b
   }

 


AlexTidmarsh - Tue Nov 18 09:10:48 EST 2014

Re: Non-polluting Buffer, Slice and attribute routines
AlexTidmarsh - Tue Nov 18 09:26:52 EST 2014

I forgot to add some examples of use:

Buffer b = createFrom( m, "Originator GROUP" )

copyTo( m, "Some other attribute", b[0:3]  )

copyTo( m, "Another Attribute", createFrom( m, "Originator GROUP" )  )

copyTo( m, "Originator GROUP", b  )


delete b